package com.seeyon.apps.ext.kingdee.util;

import java.io.Serializable;

public class RocResponse<T> implements Serializable {
    private int success = 0;  //当发生错误的时候code才有明细

    private Integer code = 0;  // 业务自定义状态码

    private String message = ""; // 请求状态描述，调试用

    private T data = null;// 请求数据，对象或数组均可

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    /**
     * 成功时候的调用
     *
     * @param data data
     * @param <T>  t
     * @return Result
     */
    public static <T> RocResponse<T> success(T data) {

        return new RocResponse<T>(data);
    }


    /**
     * 失败时候的调用
     *
     * @param code 错误code
     * @param msg  信息
     * @param <T>  数据
     * @return RocResponse
     */
    public static <T> RocResponse<T> error(int code, String msg) {
        return new RocResponse<T>(code, msg);
    }

    /**
     * 成功的构造函数
     *
     * @param data data
     */
    private RocResponse(T data) {
        this.data = data;
        this.success = 1;
    }

    private RocResponse(T data, String message) {
        this.data = data;
        this.message = message;
        this.success = 1;
    }

    private RocResponse(int code, String msg) {
        this.code = code;
        this.message = msg;
        this.success = 0;
    }

    public int getSuccess() {
        return success;
    }

    public void setSuccess(int success) {
        this.success = success;
    }
}
